﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学任务安排 - 全校通选课");
		
		termID = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		limiteB2 = event.getArg("TASK.LIMITE.B2", 3);
		limiteS3 = event.getArg("TASK.LIMITE.S3", 1);
		
		sql = "SELECT 
					t_institute.institute_id, 
					t_institute.institute_name, 
					SUM(CASE WHEN t_course.cat_id = 'B2' THEN 1 ELSE 0 END) sumCatId_B2, 
					SUM(CASE WHEN t_course.cat_id = 'S3' THEN 1 ELSE 0 END) sumCatId_S3 
				FROM 
					t_course 
					INNER JOIN  t_institute ON t_institute.institute_id = t_course.institute_id 
				WHERE 
					t_course.abandon = '0' 
				GROUP BY 
					t_institute.institute_id, t_institute.institute_name 
				ORDER BY 
					t_institute.institute_name ";
					
		queryObj = new query( datasource=application.dnsSlave );
		
		rs_ins = queryObj.execute( sql=sql ).getResult(); 
		
		
		currentTab = event.getArg("TabID", "labDepartment");
		depId = event.getArg("DepID");
		
		rs_course = queryNew("cid");
		rs_departmentEntity = queryNew("institute_name");
		
		if ( len(depId) ) {
			
			currentTab = "labCourse";
			
			sql = "SELECT institute_name FROM t_institute WHERE institute_id = :instituteId ";
			
			queryObj = new query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="instituteId", value=depId, cfsqltype="cf_sql_varchar" );
			
			rs_departmentEntity = queryObj.execute( sql=sql ).getResult();

			sql = "SELECT 
						t_course.cid, 
						t_course.course_name, 
						t_course.course_credit, 
						t_course.period_week, 
						t_course.period, 
						t_course.period_theory, 
						t_course.period_practice, 
						t_course.cat_id, 
						t_course.course_code, 
						(SELECT COUNT(*) FROM t_common_task WHERE t_common_task.term_id = :termId AND t_course.cid = t_common_task.cid) countCommonTask 
					FROM 
						t_course 
					WHERE 
						t_course.institute_id = :depId 
						AND 
						(t_course.cat_id = 'B2' OR t_course.cat_id = 'S3')
						AND 
						t_course.abandon = '0' 
				   ORDER BY 
						t_course.cat_id, t_course.course_name ";
						
			queryObj = new query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="termId", value=termID, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="depId", value=depId, cfsqltype="cf_sql_varchar" );
			
			rs_course = queryObj.execute( sql=sql ).getResult(); 
			
			writeLog( text=termID );
			writeLog( text=depId );
			
			writeDump( rs_course );
			abort;
		}
		
		passArgs = structNew();
		structInsert( passArgs, "TID", termId, true);
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<cfif len(depId)>
					<a class="uiButton" href="<cfoutput>#buildURL('commonTask')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">全校通选课教学任务</span></a>
					<cfelse>
					<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">教学任务安排</span></a>
				</cfif>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfif len(depId)><cfoutput>#rs_departmentEntity.institute_name# 通选课目录</cfoutput><cfelse>全校通选课教学任务</cfif>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labDepartment">class="active"</cfif> id="labDepartment" tabTarget="Department">任课单位</span>
						<cfif len(depId)>
							<span <cfif currentTab eq "labCourse">class="active"</cfif> id="labCourse" tabTarget="Course">课程开设情况</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
			
				<div id="Department" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton" href="<cfoutput>#buildURL('allCommonTaskUnlockDo', passArgs)#</cfoutput>"><i class="mrs img btnExecute"></i><span class="uiButtonText">解锁通选课任务</span></a>
						</div>
						<h3>任课单位</h3>
						<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期通选课教学任务由 <em><cfoutput>#rs_ins.recordCount#</cfoutput></em> 个任课单位自由开设.</p>
						<hr/>
					</div>
					
					<div class="clearfix">
						<div class="UICardTable">
                            <cfloop query="rs_ins">
								<cfset structInsert(passArgs, "DepID", rs_ins.institute_id, true) />
                                
                                <cfset sql = "SELECT COUNT(*) count FROM t_common_task INNER JOIN t_course ON t_course.cid = t_common_task.cid 
												WHERE t_common_task.term_id =:term AND t_course.institute_id = :depId "/>
								<cfset queryObj = new Query( datasource=application.dnsSlave )/>
								<cfset queryObj.addParam( name="term", value=termID, cfsqltype="cf_sql_char" )/>
								<cfset queryObj.addParam( name="depId", value=rs_ins.institute_id, cfsqltype="cf_sql_varchar" )/>
								<cfset rs_courseCount = queryObj.execute( sql=sql ).getResult()/>
                                
								<dl>
									<dt>
										<a href="<cfoutput>#buildURL('commonTask', passArgs)#</cfoutput>">
										<em class="collection"><!--imgholder--></em>
										<dd>
											<h3><cfoutput>#rs_ins.institute_name#</cfoutput></h3>
											<div><cfif rs_ins.sumCatId_B2 gt 0>素质类<cfoutput>#rs_ins.sumCatId_B2#</cfoutput>门</cfif> <cfif rs_ins.sumCatId_S3 gt 0>网络视频课<cfoutput>#rs_ins.sumCatId_S3#</cfoutput>门</cfif> <cfif rs_courseCount.recordCount gt 0>已安排<cfoutput>#rs_courseCount.count#</cfoutput>个教学任务</cfif></div>
										</dd>
										</a>
									</dt>
								</dl>
							</cfloop>
						</div>
					</div>
					
				</div>
				
				
				<div id="Course" class="tabContent">
					
					<cfif rs_departmentEntity.recordCount>
						
						<cfset passArgs = structNew() />
						<cfset structInsert( passArgs, "DepID", depId, true) />
						<cfset structInsert( passArgs, "TID", termId, true) />
						
						<div class="noticeBlock">
							<div class="operation">
								<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('commonTaskDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载通选课教学任务</span></a>
							</div>
							<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
							<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期可开设全校通选课 <em><cfoutput>#rs_course.recordCount#</cfoutput></em> 门.</p>
							<hr/>
						</div>
					
					</cfif>
					
					<cfif rs_course.recordCount>
						
						<cfset structDelete(passArgs, "DepID", false) />
						<cfset row = 0 />
						
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>课程</td>
									<td width="100">课程号</td>
									<td width="25">学分</td>
									<td width="70">排课周学时</td>
									<td width="40">总学时</td>
									<td width="50">理论学时</td>
									<td width="50">实践学时</td>
									<td width="80">任务安排进度</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
								<cfloop query="rs_course">
									<cfset row++ />
									<cfset structInsert(passArgs, "CID", rs_course.cid, true) />
									<tr class="editRows" rowid="<cfoutput>#rs_course.cid#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_course.course_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_course.course_code#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat(rs_course.course_credit, '_.__')#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_week#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_theory#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_practice#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.countCommonTask#</cfoutput> / <cfif rs_course.cat_id eq "S3"><cfoutput>#limiteS3#</cfoutput><cfelse><cfoutput>#limiteB2#</cfoutput></cfif></span></td>
										<td><a href="<cfoutput>#buildURL('commonTaskByCourse', passArgs)#</cfoutput>" class="stat <cfif rs_course.countCommonTask gt 0>running<cfelse>stop</cfif>"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
						
						<cfelse>
						
						<div class="systemNotice">
							<p>课程代码库中未设置任何素质选修课程, 请正确设置素质选修课程的课程类别</p>
						</div>
						
					</cfif>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>